package de.fmaul.common.io;

import java.io.File;

import com.google.common.base.Predicate;

public class FileNameMatchPredicate implements Predicate<File> {

	private final String name;
	private final boolean caseSensitive;
	private final boolean partialMatch;

	public FileNameMatchPredicate(String name, boolean caseSensitive,
			boolean partialMatch) {
		this.name = name;
		this.caseSensitive = caseSensitive;
		this.partialMatch = partialMatch;
	}

	public boolean apply(File input) {
		if (partialMatch) {
			if (caseSensitive) {
				return input.getName().contains(name);
			} else {
				return input.getName().toLowerCase().contains(
						name.toLowerCase());
			}
		} else {
			if (caseSensitive) {
				return input.getName().equals(name);
			} else {
				return input.getName().equalsIgnoreCase(name);
			}
		}
	};

}
